package com.njwb.controller;

import com.njwb.pojo.Dept;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Controller
public class ParameterBindController {
    //默认参数类型
    @RequestMapping("defaultBind")
    public void defaultBind(HttpServletRequest request, HttpServletResponse response,
                            HttpSession session, OutputStream os,
                            ModelAndView modelAndView, ModelMap modelMap, Map map){
        //Servlet API
        System.out.println(request);
        System.out.println(response);
        System.out.println(session);
        //响应输出流
        System.out.println(os);
        //模型数据
        System.out.println(modelAndView);
        System.out.println(modelMap);
        System.out.println(map);
    }

    //简单类型参数类型
    @RequestMapping("simpleParams")
    public void simpleParams(@RequestParam("age")Integer age,
                             @RequestParam("sal") Double sal,
                             @RequestParam("userName")String userName){
        System.out.println(age + "->" + sal + "->" + userName);
    }

    @PostMapping("pojoParams")
    public void pojoParams(Dept dept){
        System.out.println(dept);
    }

    @GetMapping("dateParam")
    public void dateParam(@RequestParam("date") Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(date));
    }


//    @RequestMapping("arrayParam")
//    public void arrayParam(@RequestParam("ids") Integer[] ids){
//        System.out.println(Arrays.toString(ids));
//    }

    @RequestMapping("arrayParam")
    public void arrayParam(@RequestParam("ids") List<Integer> ids){
        System.out.println(ids.toString());
    }
}
